import Vue from "vue";
import VueRouter from "vue-router";
import store from "../store";
Vue.use(VueRouter);

const router = new VueRouter({
    routes: [{
            path: "/",
            redirect: "/login"
        },

        {
            path: "/login",
            name: "login",
            component: () =>
                import ( /* webpackChunkName: "basepage" */ "@/pages/login/index")
        },
        {
            path: "/yunzhi",
            component: () =>
                import ("@/pages/modules/index"),
            redirect: "/dagedit",
            name: "实时流处理",
            meta: { title: "实时流处理", icon: "gwb" },
            children: [{
                path: "/dagedit",
                name: "dag",
                component: () =>
                    import ("@/pages/modules/dagEdit/index"),
                meta: { title: "dag", icon: "host" }
            }, ]
        },
        {
            // 模块不存在
            path: "/404",
            component: () =>
                import ("@/pages/404/404")
        },
        { path: "*", redirect: "/404", hidden: true }
    ]
});
// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
    next();
});

router.afterEach((to, from) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    } else {
        document.title = "";
    }
});

export default router;